package com.supermap.gwfs.datashare.util;

import com.supermap.gwfs.datashare.param.*;
import io.spring.guides.gs_producing_web_service.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhoujian
 * @version V1.0
 * @Description: 获取request传入参数
 * @date 2017-6-12
 */
public class PageData extends HashMap<String, Object> implements Map<String, Object> {
    /**
     *
     */
    private static final long serialVersionUID = 3470396696206651747L;

    Map<String, Object> map = null;
    HttpServletRequest request = null;


    public PageData() {
        map = new HashMap<String, Object>();
    }

    public PageData(HttpServletRequest request) {
        this.request = request;
        Map<String, String[]> params = request.getParameterMap();
        Map<String, Object> pageDataMap = new HashMap<String, Object>();
        String value = null;
        for (String key : params.keySet()) {
            Object valueObj = params.get(key);
            if (valueObj == null) {
                value = "";
            } else if (valueObj instanceof String[]) {
                String[] p = (String[]) valueObj;
                for (int i = 0; i < p.length; i++) {
                    value = p[i] + ",";
                }
                value = value.substring(0, value.length() - 1);
            } else {
                value = valueObj.toString();
            }
            pageDataMap.put(key, value);
        }
        map = pageDataMap;
    }

    public PageData(XXZXGRIDGetWeatherPhenomenaWithStationIdRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        pageDataMap.put("stationId", request.getStationId());
        if(!request.getForecastFileVersion().equals("manual")){
           // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        pageDataMap.put("interval", request.getInterval());
        map = pageDataMap;
    }

    public PageData(WeatherByStationIdRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        pageDataMap.put("stationId", request.getStationId());
        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        pageDataMap.put("interval", request.getInterval());
        map = pageDataMap;
    }

    public PageData(XXZXGRIDGetWeatherPhenomenaWithStationTypeOrAdminCodeRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(request.getStationType() != null && !request.getStationType().equals("")){
            pageDataMap.put("station_type", request.getStationType());
        }
        if(request.getAdminCode() != null && !request.getAdminCode().equals("")){
            pageDataMap.put("admin_code", request.getAdminCode());
        }

        if(!request.getForecastFileVersion().equals("manual")){
            //pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        pageDataMap.put("interval", request.getInterval());
        map = pageDataMap;
    }

    public PageData(WeatherByStationTypeRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(request.getStationType() != null && !request.getStationType().equals("")){
            pageDataMap.put("station_type", request.getStationType());
        }
        if(request.getAdminCode() != null && !request.getAdminCode().equals("")){
            pageDataMap.put("admin_code", request.getAdminCode());
        }

        if(!request.getForecastFileVersion().equals("manual")){
            //pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        pageDataMap.put("interval", request.getInterval());
        map = pageDataMap;
    }


    public PageData(XXZXGRIDGetNafpEleGridInRectByTimeAndLevelAndValidTimeRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin_value", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        pageDataMap.put("maxLat", String.valueOf(request.getMaxLat()));
        pageDataMap.put("maxLon", String.valueOf(request.getMaxLon()));
        pageDataMap.put("minLat", String.valueOf(request.getMinLat()));
        pageDataMap.put("minLon", String.valueOf(request.getMinLon()));
        String element = request.getElement();
        if(!element.contains(",")){
            pageDataMap.put("element_value", request.getElement());
        } else {
            pageDataMap.put("elements", request.getElement().split(","));
        }

        map = pageDataMap;
    }

    public PageData(GridInRectRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin_value", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        pageDataMap.put("maxLat", request.getMaxLat());
        pageDataMap.put("maxLon", request.getMaxLon());
        pageDataMap.put("minLat", request.getMinLat());
        pageDataMap.put("minLon", request.getMinLon());
        String element = request.getElement();
        if(!element.contains(",")){
            pageDataMap.put("element_value", request.getElement());
        } else {
            pageDataMap.put("elements", request.getElement().split(","));
        }

        map = pageDataMap;
    }

    public PageData(XXZXGRIDGetNafpEleGridInRectByTimeAndLevelAndValidAndLonAndStationIdRequest request) {

        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(request.getStationId() != null){
            pageDataMap.put("stationId", request.getStationId());
        }

        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin_value", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        String element = request.getElement();
        if(!element.contains(",")){
            pageDataMap.put("element_value", request.getElement());
        } else {
            pageDataMap.put("elements", request.getElement().split(","));
        }

        map = pageDataMap;
    }

    public PageData(GridByStationIdRequest request) {
        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(request.getStationId() != null){
            pageDataMap.put("stationId", request.getStationId());
        }

        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin_value", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        String element = request.getElement();
        if(!element.contains(",")){
            pageDataMap.put("element_value", request.getElement());
        } else {
            pageDataMap.put("elements", request.getElement().split(","));
        }

        map = pageDataMap;
    }

    public PageData(XXZXGRIDGetNafpEleGridInRectByTimeAndLevelAndValidAndLonAndStationTypeOrAdminCodeRequest request) {

        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(request.getStationType() != null && !request.getStationType().equals("")){
            pageDataMap.put("station_type", request.getStationType());
        }
        if(request.getAdminCode() != null && !request.getAdminCode().equals("")){
            pageDataMap.put("admin_code", request.getAdminCode());
        }

        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin_value", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        String element = request.getElement();
        if(!element.contains(",")){
            pageDataMap.put("element_value", request.getElement());
        } else {
            pageDataMap.put("elements", request.getElement().split(","));
        }

        map = pageDataMap;
    }

    public PageData(GridByStationTypeRequest request) {

        Map<String, Object> pageDataMap = new HashMap<String, Object>();

        if(request.getStationType() != null && !request.getStationType().equals("")){
            pageDataMap.put("station_type", request.getStationType());
        }
        if(request.getAdminCode() != null && !request.getAdminCode().equals("")){
            pageDataMap.put("admin_code", request.getAdminCode());
        }

        if(!request.getForecastFileVersion().equals("manual")){
            // pageDataMap.put("origin", request.getOrigin());
        }
        pageDataMap.put("origin_value", request.getOrigin());
        pageDataMap.put("forecast_date", request.getForecastDate());
        pageDataMap.put("sequence_value", request.getSequenceValue());
        pageDataMap.put("forecast_valid_start", request.getForecastValidStart());
        pageDataMap.put("forecast_valid_end", request.getForecastValidEnd());
        pageDataMap.put("forecast_fileversion", request.getForecastFileVersion());
        String element = request.getElement();
        if(!element.contains(",")){
            pageDataMap.put("element_value", request.getElement());
        } else {
            pageDataMap.put("elements", request.getElement().split(","));
        }

        map = pageDataMap;
    }

    @Override
    public Object put(String key, Object value) {
        return map.put(key, value);
    }

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public Object remove(Object key) {
        return map.remove(key);
    }

    @Override
    public Set<java.util.Map.Entry<String, Object>> entrySet() {
        return map.entrySet();
    }

    @Override
    public Object get(Object key) {
        return map.get(key);
    }

    public String getString(Object key) {
        return (String) get(key);
    }

    public int getInteger(Object key) {
        return Integer.valueOf(get(key).toString());
    }

}
